﻿@using MY.ShoppingBackstage.Model;
@{
    var category = ViewBag.category as Category;
    var parent = ViewBag.Parent as List<Category>;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/css/shop.css" type="text/css" rel="stylesheet" />
    <link href="~/css/Sellerber.css" type="text/css" rel="stylesheet" />
    <link href="~/css/bkg_ui.css" type="text/css" rel="stylesheet" />
    <link href="~/font/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <script src="~/layui/layui.js"></script>
    <script src="~/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="~/js/jquery.cookie.js"></script>
    <script src="~/js/shopFrame.js" type="text/javascript"></script>
    <script src="~/js/Sellerber.js" type="text/javascript"></script>
    <script src="~/js/layer/layer.js" type="text/javascript"></script>
    <script src="~/js/laydate/laydate.js" type="text/javascript"></script>
    <script type="text/javascript" src="~/js/proTree.js"></script>
    <script src="~/js/dist/echarts.js" type="text/javascript"></script>
    <script src="~/js/Maximum/Maximum.js"></script>
    <script src="~/js/jquery.dataTables.min.js"></script>
    <script src="~/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/js/hsCheckData.js" type="text/javascript"></script>
    <title>添加分类</title>
</head>
<body>
    <div class="margin inside_pages clearfix">
        <div class="add_style clearfix relative">
            <ul>
                <li class="clearfix">
                    <label class="label_name col-xs-1"><i>*</i>分类名称：&nbsp;&nbsp;</label>
                    <div class="Add_content col-xs-11">
                        <input type="hidden" id="CategoryId" value="@category.Id" />
                        <input name="" id="CategoryName" type="text" class="col-xs-6" value="@category.Name" />
                    </div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-1"><i>*</i>选择父级：&nbsp;&nbsp;</label>
                    <div class="Add_content col-xs-11">
                        <select id="CategoryParentId">

                            @foreach (var item in parent)
                            {
                                if (category.CategoryLevel == 1)
                                {
                                    <option value="0">顶级分类</option>
                                }
                                if (category.ParentId == item.Id)
                                {
                                    <option value="@item.Id" selected="selected" class="@item.CategoryLevel">@item.Name</option>
                                }
                                else
                                {
                                    <option value="@item.Id" class="@item.CategoryLevel" style="display:none">@item.Name</option>
                                }

                            }
                        </select>
                        @*<select id="CategoryParentId">
                                <option value="0">顶级分类</option>
                                @foreach (var item in parent.Where(a=>a.CategoryLevel==2))
                                {
                                    if (category.ParentId == item.Id)
                                    {
                                        <option value="@item.Id" selected="selected">@item.Name</option>
                                    }
                                    else
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }

                                }
                            </select>*@
                    </div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-1"><i>*</i>分类层级：&nbsp;&nbsp;</label>
                    <select id="CategoryCategoryLevel">
                        @if (category.CategoryLevel == 1)
                        {
                            <option value="1" selected=selected>第一级</option>
                        }
                        else if (category.CategoryLevel == 2)
                        {
                            <option value="2" selected=selected>第二级</option>
                        }
                        else if (category.CategoryLevel == 3)
                        {
                            <option value="3" selected=selected>第三级</option>
                        }
                        <option value="1">第一级</option>
                        <option value="2">第二级</option>
                        <option value="3">第三级</option>
                    </select>
                </li>
            </ul>
            <div class="Button_operation btn_width">
                <button class="btn button_btn bg-deep-blue" onclick="tijiao()" type="button">保存</button>
                <button class="btn button_btn bg-gray" type="button">取消</button>
            </div>
        </div>
    </div>
</body>
</html>
<script>

    //分类层级改变时,对应的父级选项随之变化
    $("#CategoryCategoryLevel").change(function () {
        $("#CategoryParentId").val(0);
        var index = $(this).val() - 1;
        $("#CategoryParentId option[class=" + index + "]").show();
        $("#CategoryParentId option[class!=" + index + "]").hide();
    })

    function tijiao() {
        //验证
        if ($("#CategoryCategoryLevel").val() != 1) {
            if ($("#CategoryParentId").val() == 0) {
                layer.msg("请选择对应的父级");
                return;
            }
        }
        if ($("#CategoryName").val() == "") {
            layer.msg("请输入分类名称");
            return;
        }
        var data = {};
        data.Id = $("#CategoryId").val();
        data.Name = $("#CategoryName").val();
        data.ParentId = $("#CategoryParentId").val();
        data.CategoryLevel = $("#CategoryCategoryLevel").val();
        $.ajax({
            type: "post",
            url: "/Commodity/AddOrUpdateClass",
            data: data,
            success: function (result) {
                layer.msg(result.Info, { icon: 1, time: 2000, shade: 0.2 }, function () {
                    if (result.Success) {
                        location.href = "/Commodity/ClassManager";
                    }
                });
            }
        })

    }
</script>
<script>
    $(function () {
        var ue = UE.getEditor('editor');
    });
    $(document).ready(function () {
        var spotMax = 8;
        if ($('div.images_Upload').size() >= spotMax) { $(obj).hide(); }
        $("#add_Upload").on('click', function () {
            var cid = $('.images_Upload').each(function (i) { $(this).attr('id', "Uimages_Upload_" + i) });
            addSpot(this, spotMax, cid);
        });
    });
    laydate(start);
    laydate(end);
    /*********滚动事件*********/
    $("body").niceScroll({
        cursorcolor: "#888888",
        cursoropacitymax: 1,
        touchbehavior: false,
        cursorwidth: "5px",
        cursorborder: "0",
        cursorborderradius: "5px"
    });
</script>
